// app.js
App({
	globalData: {
        url: "http://seconds.ysywy.shop"
        // url: "http://localhost:7789"
    },
    onLaunch() {
        wx.clearStorageSync()
    },
    login() {
        const secret = "1174ac6e704e3ca93e12eb5b5eeec336"
        const that = this
        wx.login({
            success(res) {
                if (res.code) {
                    // 将登录凭证发送到服务端
                    wx.request({
                        url: 'https://api.weixin.qq.com/sns/jscode2session?appid='
                            + appid + '&secret=' + secret + '&js_code=' + res.code
                            + '&grant_type=authorization_code',
                        method: 'GET',
                        success(res) {
                            wx.request({
                                url: that.data.url + "/user/login",
                                data: {
                                    openid: res.data.openid
                                },
                                success(res) {
                                    if (res.data.code == 1) {
                                        wx.setStorageSync("user", res.data.result)
                                        that.setData({ user: res.data.result })
                                        wx.showToast({ title: '登录成功' })
                                        const pages = getCurrentPages()
                                        const perpage = pages[pages.length - 1]
                                        perpage.onLoad()
                                    }
                                }
                            })
                        }
                    })
                }
            }
        })
    }
})
